import React from 'react';
import {getLsMealHistorySetMealNotice} from '../../../../api'
import {
    Modal, Form, Input, message
} from 'antd'

const AddGonggaoModule = ({ addGonggaoModuleShow, setAddGonggaoModuleShow, listFun }) => {
    const [form] = Form.useForm()
    const {validateFields, resetFields} = form;
    const handleOk = () => {
        validateFields().then(values => {
            ;(async () => {
                const {code, msg} = await getLsMealHistorySetMealNotice(values)
                if(code === '20000') {
                    message.success('公告发布成功')
                    resetFields()
                    listFun()
                    setAddGonggaoModuleShow(false);
                }else{
                    message.error(msg)
                }
            })()
        })
    };

    const handleCancel = () => {
        resetFields()
        setAddGonggaoModuleShow(false);
    };
    return <Modal title="发布公告" visible={addGonggaoModuleShow} onOk={handleOk} onCancel={handleCancel}>
        <Form
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 16 }}
            form = {form}
        >
            <Form.Item
                label="内容"
                name="notice"
                rules={[{ required: true, message: '请输入内容!' }]}
            >
                <Input maxLength = {16}/>
            </Form.Item>
        </Form>
    </Modal>
}

export default AddGonggaoModule;